<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>解决get、post乱码问题</title>
<script>
	var xmlHttp;
	try {
		//非IE、新IE
		xmlHttp = new XMLHttpRequest();
	} catch (e) {
		//IE6
		try {
			xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			//IE5.5
			try {
				xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {
				alert("不支持Ajax");
			}
		}
	}

	function doGet(num) {
		var param = encodeURIComponent(num);
		xmlHttp.open("get", "Servlet4?num=" + param);

		xmlHttp.send();
	}

	function doPost(num) {
		xmlHttp.open("post", "Servlet4");
		xmlHttp.setRequestHeader("Content-Type",
				"application/x-www-form-urlencoded");
		xmlHttp.send("num=" + num);

	}
</script>

</head>
<body>
	<center>
		get方式：<input type="text" onkeyup="doGet(this.value)"> <br />
		<div id="get" style="width:200px"></div>
		<br /> post方式:<input type="text" onkeyup="doPost(this.value)">
		<br />
		<div id="post" style="width:200px"></div>
	</center>
</body>
</html>